<?php



/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Game
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
 
class Game_Form_Admin_Distributor_Import extends Engine_Form
{
  public function init()
  {
    $this
      ->setTitle('Import Games')
      ->setDescription('Please complete the form below then proceed with importing games.');
    

    $distributorOptions = array();
    $distributors = Engine_Api::_()->getItemTable('game_distributor')->getDistributors();
    foreach( $distributors as $distributor ) {
      $distributorOptions[$distributor->type] = $distributor->getTitle();
    }

    $this->addElement('Select', 'type_id', array(
      'label' => 'Distributor Type',
      'multiOptions' => $distributorOptions,
      'onchange' => 'javascript:fetchDistributorType(this.value);',
      'ignore' => true,
    ));

    $i = 1000;
        
    
    $this->addElement('Select', 'status', array(
      'label' => 'Default Game Status',
      'description' => 'Please select default status games would have when imported. Only games with "Published" status will be viewable by your members. You can set status to "Pending", and then manually review games prior publishing them.',
      'value' => Game_Model_Game::STATUS_PENDING,
      'multiOptions' => Game_Form_Helper::getStatuses(),
      'order' => $i++,
    ));      

    $this->addElement('Radio', 'downloadswf', array(
      'label' => 'Download SWF File',
      'description' => 'Would you like to download SWF game file and save them on your server? With average of few hundred KB per file, storing game files may use a lot of your server space and slow down import process, so only download them if neccessary. Please note that in order to earn money with MochiAds, you will need to host the game\'s SWF file on your own server, and verify your domain in Mochi\'s Publisher settings on Mochi website. Recommend you to only check YES when importing Mochi games with "Published" status, and want to earn money with MoneyAds. Some games may NOT work (black-screen) if you host it on your server, in such case, you must use hot-link method. You can always manually download SWF files later on "View Games" page whenever you want to.',
         
      'multiOptions' => array(
        0 => 'No, hot-linked game SWF file from distributor',
        1 => 'Yes, download and store game SWF file on server' 
      ),
      'value' => 0,
      'order' => $i++,
    ));
    
    $this->addElement('Radio', 'downloadphoto', array(
      'label' => 'Download Photo File',
      'description' => 'Would you like to download game photo file and save them on your server? If game distributor allow you to hot-link photo files (most are), then you do NOT need to download game photo file. Hot-linked files allow you to save server space / bandwidth.',
         
      'multiOptions' => array(
        0 => 'No, hot-linked game photo file from distributor',
        1 => 'Yes, download and store game photo file on server' 
      ),
      'value' => 0,
      'order' => $i++,
    ));    
    
    
    $this->addElement('Text', 'limit', array(
      'label' => 'Limit',
      'description' => "You can limit the number of games returned in the feed. Recommended limit is 100 or less depending on your server performance and load. If you get time-out/execution error or choose to download swf/photo files in options above, you should change to a smaller limit number.",
      'value' => 50,
      'allowEmpty' => false,
      'required' => true,
      'validators' => array(
        'Int',
        new Zend_Validate_GreaterThan(0),
      ),  
      'order' => $i++,  
    )); 
      
    $this->addElement('Text', 'offset', array(
      'label' => 'Offset',
      'description' => "You can also use the offset parameter to fetch older games in smaller chunks. OFFSET=(n) is to get games from the (n)th game in the list (in other words, it is to skip that many games from the begining). Let's say you have LIMIT=50, the offset would be any number multiple of 50, such as 0, 50, 100, 150, or 200 etc.. Entering LIMIT=50, OFFSET=100 mean retrieving maximum 50 games from position 101th (ie skip the first 100 games).",
      'value' => 0,
      'allowEmpty' => false,
      'required' => true,
      'validators' => array(
        'Int',
        new Engine_Validate_AtLeast(0),
      ),
      'order' => $i++,
    ));    
    
    // Add submit button
    $this->addElement('Button', 'submit', array(
      'label' => 'Import Games',
      'type' => 'submit',
      'ignore' => true,
      'order' => $i++,
    ));
  }
}